<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@include file="connexion.jsp"%>

<%
	String ch = "", model = "", ch1 = "";
	int relation;
	model = request.getParameter("model");
	ch = request.getParameter("ch");
	ch1 = request.getParameter("ch2");
	relation = Integer.parseInt(ch1);
%>
<html>
<head>
<%@ page language="java" import="java.util.StringTokenizer"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%
		StringTokenizer st = new StringTokenizer(ch);
		if (st.countTokens() == 2) {
			int n = 0;
			int[] tab = new int[3];
			while (st.hasMoreTokens()) {
				tab[n] = Integer.parseInt(st.nextToken());
				n++;
			}
			Connection con = null;
			String URL = "jdbc:mysql://localhost:3306/" + model;
			//compter les ligne deja existantes
			con = DriverManager.getConnection(URL, "root", "metanote");
			int id_contenu = 0;
			try {
				stmt = con.createStatement();
				ResultSet r = stmt
						.executeQuery("select max(id_contenu_relation) from contenus_en_relation");
				r.last();
				id_contenu = r.getInt(1);
			}

			catch (Exception e) {
				out.println("une exception " + e.getMessage());
			}
			id_contenu++;
			out.println(id_contenu);
			String req2 = "INSERT INTO contenus_en_relation (id_contenu_relation, id_contenu1, id_relation1, id_contenu2) VALUES("
					+ id_contenu
					+ ","
					+ tab[1]
					+ ","
					+ relation
					+ ","
					+ tab[0] + ");";
			try {
				stmt.executeUpdate(req2);

			} catch (Exception ex) {
				out.println("Err" + ex.getMessage());
			}
			out.println("Insertion Effectuer ");
		} else
			out.println("Selectionner deux termes");
	%>
</body>
</html>